﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GeoWeb.Demo.GeoFullTextSearch
{
    public partial class SearchDemo : System.Web.UI.Page
    {
        GeoWeb.FullTextSearchLib.FullTextSearch MySeach;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.Params["queryString"]))
                Search(Request.Params["queryString"].Trim());
            if(MySeach==null)
                MySeach = new GeoWeb.FullTextSearchLib.FullTextSearch();
        }

        //查询
        private void Search(string keyWord)
        {
            //查询关键词
            //GeoFullTextSearchLib.GeoFullTextSearch MySeach = new GeoFullTextSearchLib.GeoFullTextSearch();
            if (MySeach == null)
                MySeach = new GeoWeb.FullTextSearchLib.FullTextSearch();

            string strOutput = MySeach.Search(keyWord, 0, 50);
            string title = "记录数：" + MySeach.Count + "条   用时：" + MySeach.Time + "秒</br></br>";
            string content = strOutput;
            Response.ContentType = "text/plain";
            Response.Write(title + "&" + content);
        }

        //建立索引
        private void CreateIndex()
        {
            if (MySeach == null)
                MySeach = new GeoWeb.FullTextSearchLib.FullTextSearch();

            //GeoFullTextSearchLib.GeoFullTextSearch mySearch = new GeoFullTextSearchLib.GeoFullTextSearch();
            MySeach.CreateIndex();
        }


        protected void Button2_Click(object sender, EventArgs e)
        {
            CreateIndex();
        }
    }
}